/*
 * Copyright (c) 2012 Keerthi Ramachandran .
 */
package com.kee.example.runner;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import com.kee.example.dao.PersonDao;
import com.kee.example.domain.Event;
import com.kee.example.domain.Person;

/**
 * This class... todo (RK) javadoc
 *
 * @author <a href="mailto:Keerthi.Ramachandran@navis.com">Keerthi Ramachandran</a>, 8/23/12
 * @since 2.4. /2012-08-23
 */
public class PersonRunner {

    private static final String FIRST_NAME = "First_name";
    private static final String LAST_NAME = "LastName";
    private static final String EMAIL_1 = "email1";
    private static final String EVENT_STRING = "EventString";
    private static final String EVENT2 = "Event2";

    public static void main(String[] args) {
        PersonRunner personRunner = new PersonRunner();
        personRunner.initData();
        personRunner.popAndPrintData();
    }

    private void popAndPrintData() {
        Person person = (new PersonDao()).getPerson(FIRST_NAME, LAST_NAME);
        System.out.println("person.getFirstName() = " + person.getFirstName());
        System.out.println("person.getId() = " + person.getId());
        System.out.println("person.getLastName() = " + person.getLastName());
        Set<Event> eventSet = person.getEvents();
        for(Event event:eventSet){
            System.out.println("event.getId() = " + event.getId());
            System.out.println("event.getEventString() = " + event.getEventString());
            System.out.println("event.getEventDate() = " + event.getEventDate());
        }
    }

    private void initData() {
        Person person = new Person();
        person.setFirstName(FIRST_NAME);
        person.setLastName(LAST_NAME);
        Set email = new HashSet(1);
        email.add(EMAIL_1);
        person.setEmailAddress(email);
        Set<Event> eventSet = new HashSet<Event>(2);
        Event event = new Event();
        event.setEventDate(new Date());
        event.setEventString(EVENT_STRING);
        eventSet.add(event);
        Event event1 = new Event();
        event1.setEventDate(new Date());
        event1.setEventString(EVENT2);
        eventSet.add(event1);

        person.setEvents(eventSet);
        PersonDao personDao = new PersonDao();
        personDao.save(person);
    }
}
